
/**
	Name                 :  Stephen Durfey
	Course Number        : CS462
	Semester         :  Spring 2009
    Assignment      : 8
    Due Date          : Thursday, April 23rd, 12:00pm
	
    Description: This program is a simple database application that will perform
			specified select statements on a set of three relations
            .DEPARTMENT, .INTERSECTION, and FACULTY. The user will be able
            to select what type of query they would like to
            perform, they have two options: a query on the
            department, which will return a list of all faculty
            members in that department (if any), and a query on
            a particular faculty member, which will return all
            departments associated with that faculty member. If
            no results are found, the user is notified. Several
            Functions have been added to version 8 of this piece
            of software. It provides functionality for
            modifying, deleting, and inserting data into various
            relations.
*/

#include <iostream>
#include <string>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

using namespace std;

//Declare Section

EXEC SQL BEGIN DECLARE SECTION;

    char               addDeptName[50], 
	                   addDeptLocation[50], 
	                   addDeptPhone[15],
					   addFacultyName[30],
					   addFacultyRank[12],
		               addFacultyYearStart[5],
					   addFacultyOffice1[30],
		               addFacultyOffice2[30],
		               addFacultyOffice3[30],
		               addFacultyPhone1[15],
		               addFacultyPhone2[15],
		               addFacultyPhone3[15],
					   modifyDeptName[50],
				       modifyDeptLocation[50],
					   modifyDeptPhone[15],
					   modifyFacultyName[30],
		               modifyFacultyRank[12],
		               modifyFacultyYearStart[5];
				
    int                addDeptNum,
					   addFacultyNum,
					   dept11,
		               dept4,
					   modifyDeptNum,
					   modifyFacultyNum,
					   faculty;

	VARCHAR            username[20];
	VARCHAR            password[20];
	VARCHAR            sqlStatement[800];

	unsigned int       departmentNum;
	unsigned int       facultyNum;

	unsigned int       DS_DeptNum;
	VARCHAR            DS_DeptName[30];
	VARCHAR            DS_DeptLocation[30];
	VARCHAR            DS_DeptPhone[12];

	unsigned int       DS_FacNum;
	unsigned int       DS_FacYearStart;
	VARCHAR            DS_FacName[20];
	VARCHAR            DS_FacRank[4];

	unsigned int       DS_IDeptNum;
	unsigned int       DS_IFacNum;
	VARCHAR            DS_IOffice[30];
	VARCHAR            DS_IPhone[12];

EXEC SQL END DECLARE SECTION;

//include SQL communications area

EXEC SQL INCLUDE SQLCA;

//function declarations

void connect();  //connects to Oracle
void buildSqlSelectDepartment( string department ); //builds specified sql statement for a department query
void buildSqlSelectFaculty( string faculty );    //builds specified sql statement for a faculty member query
void prepareExecute( string queryType ); //creates cursor and executes sql statement
void printResultsDepartment(); //prints out results from select statement on a department
void printResultsFaculty(); //prints out results from select statement on a faculty member
void commit(); //severs Oracle connection
void sqlErrorHandle(char *); //handles errors in SQL code
void notFound(  ); //called whenver the select statement doesnt return any tuples
void deleteEmptyDepartment( ); //deletes department without any faculty members
void deleteDepartmentTwoOrMore( string department ); //deletes a department with two or more faculty members
void printResultsTwoOrMore( string department ); //prints faculty info 
void deleteOrphanFaculty( string facultyNum ); //deletes a faculty member that does not belong to a department
void deleteFacultyTwoOrMore( string facultyNum );
void addDepartment(); //adds new department to the department relation
void printNewDepartment(); //prints new department information
void addFaculty(); //adds a new faculty member 
void prepareCursor(); //prepares cursor for select statement
void modifyDeptTuple();
void modifyFacTuple();

int counter = 0;
int deleteCounter = 0; //used in deleteDepartmentTwoOrMore to print proper headings

int main()
{
	int decision = 0;
	string department;
	string facultyNum;
	
	//defines which function to call in case of an SQL error
	EXEC SQL WHENEVER SQLERROR do sqlErrorHandle("***Oracle Error:  ");
	
	//connects to DB
	connect();
	
	cout << "Welcome to the interoffice database search application!\n";
	cout << "Specify a search type below, please\n\n";
	
	//displays menu for user to select options from, continues to loop until the user presses '3'
	//to exit the proram, which will call the commit function
	do
	{
		cout  << "(1)  Department Query     \n";
		cout  << "(2)  Faculty Member Query \n";
		cout  << "(3)  Delete Empty Department\n";
		cout  << "(4)  Delete Department With Two or More\n";
		cout  << "(5)  Delete Departmentless Faculty\n";
		cout  << "(6)  Delete Faculty In Two or More Department\n";
		cout  << "(7)  Add New Department\n";
		cout  << "(8)  Add New Faculty Member\n";
		cout  << "(9)  Modify Department Record\n";
		cout  << "(10) Modify Faculty Record\n";
		cout  << "(11) Exit\n";
		cout  << "Enter choice: ";
		cin   >> decision;

		if( decision == 1 )
		{
			cout << "\n\nEnter Department Number: ";
			cin  >> department;
			buildSqlSelectDepartment( department );
			prepareCursor();
			prepareExecute( "department" );
		}
		else if( decision == 2 )
		{
			cout << "\n\nEnter Faculty Number: ";
			cin  >> facultyNum;
			buildSqlSelectFaculty( facultyNum );
			prepareCursor();
			prepareExecute( "faculty" );
		}
		else if( decision == 3 )
		{
			cout << "\n\nEnter Department Number: ";
			cin  >> departmentNum;
			deleteEmptyDepartment( );
		}
		else if( decision == 4 )
		{
			cout << "\n\nEnter Department Number: ";
			cin  >> department;
			deleteDepartmentTwoOrMore( department );
		}
		else if( decision == 5 )
		{
			cout << "\nEnter Faculty Number: ";
			cin  >> facultyNum;
			deleteOrphanFaculty( facultyNum );
		}
		else if( decision == 6 )
		{
			cout << "Enter Faculty Number: ";
			cin  >> facultyNum;
			deleteFacultyTwoOrMore( facultyNum );
		}
		else if( decision == 7 )
		{
			addDepartment();
		}
		else if( decision == 8 )
		{
			addFaculty();
		}
		else if( decision == 9 )
		{
			modifyDeptTuple();
		}
		else if( decision == 10 )
		{
			modifyFacTuple();
		}
		
		if( decision < 1 || decision > 11 )
		{
			cout << "I am sorry, I cannot process your request, please select the correct option from the menu, thank you\n\n\n";
		}
		
	}
	while( decision != 11 );
	
	commit();

	return 0;
}//end of main function

/**
 * asks for username and password, and attempts to connect to 
 * Oracle 
 * 
 * @author stephen (4/23/2009)
 */
void connect()
{
	//gathers the Oracle username and password
	char* temp_password;

	cout << "Enter Oracle Username: ";
	cin >> username.arr;

	temp_password = getpass("Enter Oracle Password: ");
	strcpy((char*)password.arr, temp_password);

	//gets length of username and password
	username.len = strlen( (char*) username.arr );
	password.len = strlen( (char*) password.arr );

	//connects to Oracle, with the specified username and password
	EXEC SQL CONNECT :username IDENTIFIED BY :password;

	cout << "Connected to Oracle as user: " << (char*) username.arr << endl << endl;

}//end of connect function


/**
 *builds the SQL select query, each time the function is called,
 *the user is prompted to enter a department number, which is 
 *then catatenated onto the end of the SELECT statement, and 
 *subsequently printed to the screen for your viewing pleasure. 
 * 
 * @author stephen (4/23/2009)
 */
void buildSqlSelectDepartment( string department )
{
	strcpy( (char*) sqlStatement.arr,  "SELECT   INTERSECTION.IDeptNum, DEPARTMENT.DeptName,\n"
									   "         DEPARTMENT.DeptLocation, INTERSECTION.IFacNum,\n"
									   "         FACULTY.FacName, INTERSECTION.IOffice,\n"
									   "         INTERSECTION.IPhone, FACULTY.FacRank, FACULTY.FacYearStart\n"
									   "FROM     DEPARTMENT\n"
									   "JOIN     INTERSECTION\n"
									   "ON       DEPARTMENT.DeptNum = INTERSECTION.IDeptNum\n"
									   "JOIN     FACULTY\n"
									   "ON       INTERSECTION.IFacNum = FACULTY.FacNum\n"
									   "WHERE    DEPARTMENT.DeptNum = ");

	strcat( (char*) sqlStatement.arr, department.c_str() );
								
	cout << "Query is:  \n" << sqlStatement.arr << endl; 
}//end of buildSqlSelectDepartment function

/**
 * builds the SQL select query, each time the function is
 * called, the user is prompted to enter a faculty member 
 * number, which is then catatenated onto the end of the SELECT
 * statement, and subsequently printed to the screen for your
 * viewing pleasure.
 * 
 * @author stephen (4/23/2009)
 */
void buildSqlSelectFaculty( string faculty )
{
	
	
	strcpy( (char*) sqlStatement.arr,  "SELECT   INTERSECTION.IDeptNum, DEPARTMENT.DeptName,\n"
									   "         DEPARTMENT.DeptLocation, INTERSECTION.IFacNum,\n"
									   "         FACULTY.FacName, INTERSECTION.IOffice,\n"
									   "         INTERSECTION.IPhone, FACULTY.FacRank, FACULTY.FacYearStart\n"
									   "FROM     FACULTY\n"
									   "JOIN     INTERSECTION\n"
									   "ON       FACULTY.FacNum = INTERSECTION.IFacNum\n"
									   "JOIN     DEPARTMENT\n"
									   "ON       INTERSECTION.IDeptNum = DEPARTMENT.DeptNum\n"
									   "WHERE    FACULTY.FacNum = ");

	strcat( (char*) sqlStatement.arr, faculty.c_str() );
								
	cout << "Query is:  \n" << sqlStatement.arr << endl;
} //end of buildSqlSelectFaculty function

/**
 * called before executing buildSqlSelectDepartment and 
 * buildSqlSelectFaculty methods. prepares cursor for fetch 
 * statement 
 * 
 * @author stephen (4/23/2009)
 */
void prepareCursor()
{
	sqlStatement.len = strlen( (char*) sqlStatement.arr );

	//prepares SQL select statement
	
	EXEC SQL PREPARE S1 FROM :sqlStatement;
	//associate cursor with a prepared sql statement
	
	EXEC SQL DECLARE C1 CURSOR FOR S1;
	//open the cursor, execute SQL statement, place tuples in the cursor
	EXEC SQL OPEN C1;
}//end prepareCursor method


/**
 * used by buildSqlSelectDepartment and 
 * buildSqlSelectFaculty methods for retrieving data from the 
 * database. 
 * 
 * @author stephen (4/23/2009)
 */
void prepareExecute( string queryType )
{
	//keeps track on number of iterations, used in three functions, notFound, 
	//printResultsDepartment, and printResultsFaculty
	counter = 0; 
	
	//loops through the cursor, and extracts the data, and stores that data into each variable in the
	//declare section, as specified 
	do
	{
		//if zero tuples were selected from DB, call the function notFound
		EXEC SQL FETCH C1 INTO  DS_IDeptNum,
								DS_DeptName,
								DS_DeptLocation,
								DS_IFacNum,
								DS_FacName,
								DS_IOffice,
								DS_IPhone,
								DS_FacRank,
								DS_FacYearStart;

		if( sqlca.sqlcode == 0 )
		{
			if( queryType == "department" )
				printResultsDepartment();
			else
				printResultsFaculty();
		}
		else if( sqlca.sqlcode > 0 )
		{
			notFound();
		}
			
		counter++;
		
	}
	while( sqlca.sqlcode == 0 ); //end of retrieve do-while loop
	
	cout << endl << endl;
	counter = 0;
	
}//end of prepareExecute function

/**
 * called and printed if no rows were selected from the database
 * if counter is equal to 0, then it means this function was
 * called during the first iteration of the do-while loop in the
 * previous function, prepareExecute() 
 * 
 * @author stephen (4/23/2009)
 */
void notFound()
{
	if( counter == 0 )
		cout << "\n\nNo tuples found matching the requested statement\n\n";
}//end of notFound function

/**
 * deletes an empty department
 * 
 * @author stephen (4/23/2009)
 */
void deleteEmptyDepartment(  )
{
	//grabs the name of the department to be deleted
	EXEC SQL DECLARE C3 CURSOR FOR 
	   SELECT DeptName
	   FROM   DEPARTMENT
	   WHERE  DeptNum = :departmentNum;
	EXEC SQL OPEN C3;

	EXEC SQL FETCH C3 INTO DS_DeptName;

	//delete department
	EXEC SQL DELETE FROM DEPARTMENT WHERE DEPTNUM = :departmentNum;

	//verifies department was deleted
	EXEC SQL DECLARE C2 CURSOR FOR
	   SELECT DeptNum 
	   FROM   DEPARTMENT
	   WHERE  DeptNum = :departmentNum;
	EXEC SQL OPEN C2;

	EXEC SQL FETCH C2 INTO DS_DeptNum;
}//end deleteEmptyDepartment

/**
 * deletes a department that has more than one faculty member. 
 * a list of faculty members whom are affected by the deletion 
 * of the department will be listed 
 * 
 * @author stephen (4/23/2009)
 * 
 * @param department 
 */
void deleteDepartmentTwoOrMore( string department )
{
	departmentNum = atoi( department.c_str() );
	//retrieves the names of affected faculty members
	EXEC SQL DECLARE C4 CURSOR FOR 
	   SELECT  FacName, DeptName
	   FROM    FACULTY, INTERSECTION, Department
	   WHERE   INTERSECTION.IDeptNum = :departmentNum
       AND     INTERSECTION.IFacNum = FACULTY.FacNum
       AND     DEPARTMENT.DeptNum = :departmentNum;
	EXEC SQL OPEN C4;

	do
	{	
		EXEC SQL FETCH C4 INTO DS_FacName,
                               DS_DeptName;
		
		if( sqlca.sqlcode == 0 )
		{
			printResultsTwoOrMore( department );
		}

		deleteCounter++;
	}
	while( sqlca.sqlcode == 0 );

	deleteCounter = 0;
	cout << endl << endl;

	//deletes intersection records
	EXEC SQL DELETE FROM  INTERSECTION
                    WHERE INTERSECTION.IDeptNum = :departmentNum;

	//deletes department records
	EXEC SQL DELETE FROM  DEPARTMENT
					WHERE DEPARTMENT.DeptNum = :departmentNum;

}//end deleteDepartmentTwoOrMore method

/**
 *  prints the affected faculty members from the deletion of the
 *  specified department
 * 
 * @author stephen (4/22/2009)
 * 
 * @param department 
 */
void printResultsTwoOrMore( string department )
{
	if( deleteCounter == 0 )
	{
		cout << "------------------- Department -----------------------\n\n";
		cout << "                 " << (char*)DS_DeptName.arr << "                                 \n";
		cout << "              Faculty Affected By Delete                             \n\n";
		cout << "----------------------------------------------------------\n";
		cout << "           Name\n";
		cout << "     ===============\n\n";
 	}
	else
	{
		cout << "     " << (char *)DS_FacName.arr << endl;
	}

	strcpy( (char *)DS_FacName.arr, "                ");

}//end printResultsTwoOrMore method

/**
 * description: this method deletes a faculty member from the 
 * faculty relation that does not belong to any department 
 * 
 * @author stephen (4/22/2009)
 */
void deleteOrphanFaculty( string facultyNum )
{
	int faculty = atoi( facultyNum.c_str() );
	//deletes the specified faculty member from the faculty relation
	EXEC SQL DELETE FROM   FACULTY
                    WHERE  FacNum 
	                NOT IN (SELECT IFacNum FROM INTERSECTION)
                    AND    FacNum = :faculty;

	//queries relation to verify deletion
	EXEC SQL DECLARE C6 CURSOR FOR
	   SELECT FacName
	   FROM   FACULTY
	   WHERE  FacNum = :faculty;
	EXEC SQL OPEN C6;

	do
	{	
		EXEC SQL FETCH C6 INTO DS_FacName;
	}
	while( sqlca.sqlcode == 0 );

	if( sqlca.sqlcode > 0 )
	{
		cout << "Faculty Member with ID of " << faculty << " has been deleted successfully\n\n";
	}
}//end deleteOrphanFaculty method

/**
 * deletes a faculty member that is involved in more than one 
 * department. 
 * 
 * @author stephen (4/23/2009)
 */
void deleteFacultyTwoOrMore( string facultyNum )
{
	int faculty = atoi( facultyNum.c_str() );
	//deletes intersection records
	EXEC SQL DELETE FROM INTERSECTION
       WHERE IFacNum = :faculty;

	//deletes faculty record
	EXEC SQL DELETE FROM FACULTY
	   WHERE FacNum = :faculty;
	
}//end deleteFacultyTwoOrMore method

/**
 * description: adds a new department to the department 
 * relation, then prints out the new department information 
 *  
 * known issue: not being inserted
 * 
 * @author stephen (4/22/2009)
 */
void addDepartment()
{
	cout << "Please Enter a Department Name: ";
	cin  >> addDeptName;
	cout << "Please Enter a Department Location: ";
	cin  >> addDeptLocation;
	cout << "Please Enter a Department Phone Number: ";
	cin  >> addDeptPhone;
	cout << "Please Enter a Department Number: ";
	cin  >> addDeptNum;

	cout << addDeptNum << endl;

	EXEC SQL INSERT INTO DEPARTMENT(DEPTNUM, DEPTNAME, DEPTLOCATION, DEPTPHONE)
	   VALUES(:addDeptNum, :addDeptName, :addDeptLocation, :addDeptPhone);

	EXEC SQL DECLARE C7 CURSOR FOR
	   SELECT DeptNum, DeptName, DeptLocation, DeptPhone
	   FROM   DEPARTMENT
	   WHERE  DeptNum = :addDeptNum;
	EXEC SQL OPEN C7;

	EXEC SQL FETCH C7 INTO DS_DeptNum,
                           DS_DeptName,
                           DS_DeptLocation,
                           DS_DeptPhone;

	printNewDepartment();
}//end addDepartment method

/**
 * prints department info, called from addDepartment
 * 
 * @author stephen (4/22/2009)
 */
void printNewDepartment()
{

	cout << "\n\n\n---------------------------------- Department -----------------------------------\n";
		
	cout << "               Depart Num :  " <<  DS_DeptNum                 << endl;
	cout << "               Depart Name:  " << (char*) DS_DeptName.arr      << endl;
	cout << "               Location   :  " << (char*) DS_DeptLocation.arr  << endl;       
	cout << "               Phone      :  " << (char*) DS_DeptPhone.arr     << endl;

	cout << "--------------------------------------------------------------------------------------\n\n\n";
	
}//ends printNewDepartment method

/**
 * adds to faculty member to the faculty relation. the new 
 * faculty member will be inserted into departments 11, 4, 
 * and another department, as specified by the user. A query 
 * will then be performed and display the department information 
 * for the new faculty member. 
 * 
 * @author stephen (4/22/2009)
 */
void addFaculty()
{
	dept11 = 11;
	dept4 = 4;
	cout << "Please Enter a Faculty Name: ";
	cin  >> addFacultyName;
	cout << "Please Enter a Faculty Rank: ";
	cin  >> addFacultyRank;
	cout << "Please Enter a Faculty Year Start: ";
	cin  >> addFacultyYearStart;
	cout << "Please Enter a Faculty Number: ";
	cin  >> addFacultyNum;
	cout << "Please Enter Faculty Office in Dept 11: ";
	cin  >> addFacultyOffice1;
	cout << "Please Enter Faculty Phone in Dept 11:  ";
	cin  >> addFacultyPhone1;
	cout << "Please Enter Faculty Office in Dept 4: ";
	cin  >> addFacultyOffice2;
	cout << "Please Enter Faculty Phone in Dept 4 ";
	cin  >> addFacultyPhone2;
	cout << "Please Enter a Department Num for Faculty Member: ";
	cin  >> addDeptNum;
	cout << "Please Enter Faculty Office in New Department: ";
	cin  >> addFacultyOffice3;
	cout << "Please Enter Facutly Phone in New Deptartment: ";
	cin  >> addFacultyPhone3;

	EXEC SQL INSERT INTO FACULTY(FACNUM, FACNAME, FACRANK, FACYEARSTART)
	   VALUES(:addFacultyNum, :addFacultyName, :addFacultyRank, :addFacultyYearStart);

	EXEC SQL INSERT INTO INTERSECTION(IDEPTNUM, IFACNUM, IOFFICE, IPHONE)
	   VALUES(:dept11, :addFacultyNum, :addFacultyOffice1, :addFacultyPhone1);

	EXEC SQL INSERT INTO INTERSECTION(IDEPTNUM, IFACNUM, IOFFICE, IPHONE)
	   VALUES(:dept4, :addFacultyNum, :addFacultyOffice2, :addFacultyPhone2);

	EXEC SQL INSERT INTO INTERSECTION(IDEPTNUM, IFACNUM, IOFFICE, IPHONE)
	   VALUES(:addDeptNum, :addFacultyNum, :addFacultyOffice3, :addFacultyPhone3);

}//end addFaculty method

/**
 * description: prompts the user for information to modify the 
 * specified department number. 
 * 
 * @author stephen (4/23/2009)
 */
void modifyDeptTuple()
{
	cout << "Please Enter A Department Number to Modify: ";
	cin  >> modifyDeptNum;
	cout << "Please Enter Department Name Change: ";
	cin  >> modifyDeptName;
	cout << "Please Enter Department Location Change: ";
	cin  >> modifyDeptLocation;
	cout << "Please Enter Department Phone Change: ";
	cin  >> modifyDeptPhone;

	EXEC SQL UPDATE DEPARTMENT
	   SET   DeptName     = :modifyDeptName,
             DeptLocation = :modifyDeptLocation,
             DeptPhone    = :modifyDeptPhone
	   WHERE DeptNum      = :modifyDeptNum;

    cout << endl << endl;
}//end modifyDeptTuple method

/**
 * prompts the user to enter the data to modify a faculty 
 * member. however, FacYearStart will not be modified in this 
 * method. 
 * 
 * @author stephen (4/23/2009)
 */
void modifyFacTuple()
{
	cout << "Please Enter a Faculty Number to Modify: ";
	cin  >> modifyFacultyNum;
	cout << "Please Enter Faculty Name Change: ";
	cin  >> modifyFacultyName;
	cout << "Please Enter Faculty Rank Change: ";
	cin  >> modifyFacultyRank;
	
	EXEC SQL UPDATE FACULTY
	   SET   FacName   = :modifyFacultyName,
             FacRank   = :modifyFacultyRank
	   WHERE FacNum    = :modifyFacultyNum;

	cout << endl << endl;
}//end modifyFacTuple method

 /**
  * prints the results of each department, by listing all faculty
  * memebers of that department 
  * 
  * @author stephen (4/23/2009)
  */
 void printResultsDepartment( )
 {
	//prints header information for department being queried
	if( counter == 0 )
	{
		cout << "\n\n\n---------------------------------- Department -----------------------------------\n";
		
		cout << "               Depart Num :  " <<  DS_IDeptNum                 << endl;
		cout << "               Depart Name:  " << (char*) DS_DeptName.arr      << endl;
		cout << "               Location   :  " << (char*) DS_DeptLocation.arr  << endl;       
		
		cout << "----------------------------------- Faculty Member(s) ---------------------------------\n\n";
		cout << "    Name             Num         Office            Phone         Rank      Start Year\n";
	    cout << "============        =====   =================  =============    ========  ===========\n\n";
	}//end of print header if statement
	
	//prints specified variables in a uniform and formatted way
	cout << setw(20) << left << (char *) DS_FacName.arr;
	cout << setw(8)  << left << DS_IFacNum;
	cout << setw(19) << left << (char *) DS_IOffice.arr;
	cout << setw(17) << left << (char *) DS_IPhone.arr; 
	cout << setw(10) << left << (char *) DS_FacRank.arr;
	cout << setw(10) << left << DS_FacYearStart << endl;
	
	
	strcpy( (char *) DS_DeptName.arr,     "                 " );
	strcpy( (char *) DS_DeptLocation.arr, "                 " );
	strcpy( (char *) DS_IOffice.arr,      "                 " );
	strcpy( (char *) DS_FacName.arr,      "                 " );
	strcpy( (char *) DS_IPhone.arr,       "                 " );
	strcpy( (char *) DS_FacRank.arr,      "                 " );

 } //end print deparment function
 
 /**
 *   prints results of each faculty memeber specified, byprinting
 *   out the department information for each department the
 *   faculty member is a member of.
 * 
  * @author stephen (4/23/2009)
  */
 void printResultsFaculty( )
 {
	//prints header only once. the counter variable ensures this
	if( counter == 0 )
	{
		cout << "\n\n\n-------------------------- Faculty Member ------------------------------\n";
		
		cout << "               Faculty Num:  " <<  DS_IFacNum                  << endl;
		cout << "               Name       :  " << (char*) DS_FacName.arr       << endl;
		cout << "               Rank       :  " << (char*) DS_FacRank.arr       << endl;
		cout << "               Year Start :  " <<  DS_FacYearStart             << endl;       
		
		cout << "---------------------------- Department(s)  ----------------------------\n\n";
		cout << "  Num      Department Name           Office            Location           Phone\n";
		cout << " =====   ===================    ================    ==============     =============\n";
	}//end print header if statment
	
	//prints output from variables in the declare section
	cout << "   " << setw(8)   << left << DS_IDeptNum;
	cout << setw(22)  << left << (char*) DS_DeptName.arr;
	cout << setw(19)  << left << (char *) DS_IOffice.arr;
	cout << setw(20)  << left << (char*) DS_DeptLocation.arr; 
	cout << setw(10)  << left << (char*) DS_IPhone.arr << endl;

	strcpy( (char *) DS_DeptName.arr,     "                 " );
	strcpy( (char *) DS_DeptLocation.arr, "                 " );
	strcpy( (char *) DS_IOffice.arr,      "                 " );
	strcpy( (char *) DS_FacName.arr,      "                 " );
	strcpy( (char *) DS_IPhone.arr,       "                 " );
	strcpy( (char *) DS_FacRank.arr,      "                 " );

 } //end print faculty function
 
/**
 * commits work performed on database and severs connection
 * 
 * @author stephen (4/23/2009)
 */
void commit()
{
	EXEC SQL COMMIT WORK RELEASE;
}//end commit function

/**
 * error handler used everytime an SQL error is generated in
 * Oracle, could be an incorrect login name/password or an error
 * in SQL syntax
 * 
 * @author stephen (4/23/2009)
 * 
 * @param message 
 */
void sqlErrorHandle( char * message )
{
	EXEC SQL WHENEVER SQLERROR CONTINUE;
	
	cout << endl << message << endl;
	cout << sqlca.sqlerrm.sqlerrmc << endl;
	
	EXEC SQL ROLLBACK RELEASE;
	
	exit(1);
} //end sqlError function
